package com.example.cloud.controller.personal;

import com.example.cloud.controller.common.BaseController;
import com.example.cloud.model.dto.QueryModel;
import com.example.cloud.model.dto.Result;
import com.example.cloud.model.personal.WorkOrder;
import com.example.cloud.service.personal.WorkOrderService;
import com.example.cloud.utils.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;

/**
 * Created by wangtao on 2018/5/22.
 */
@RestController
@RequestMapping("/work")
public class WorkController extends BaseController {

    private Logger logger = LoggerFactory.getLogger(WorkController.class);

    @Autowired
    private WorkOrderService workOrderService;

    @PostMapping("/search")
    public Result search(@RequestBody QueryModel model) {
        return this.singleQuery(model, WorkOrder.class);
    }

    @GetMapping("/findByUser")
    public Result findByAccept(){
        return ResultUtil.success(workOrderService.findListdByUser());
    }

    @PostMapping("/saveOrUpdate")
    public void saveOrUpdate(@RequestBody WorkOrder record) throws ParseException {
        workOrderService.doSave(record);
    }

    @PostMapping("/accept")
    public void accept(@RequestBody WorkOrder record) throws ParseException {
        workOrderService.doAccept(record);
    }

    @PostMapping("/resolve/{id}")
    public void resolve(@PathVariable Long id){
        workOrderService.doResolve(id);
    }

    @PostMapping("/auditComplete/{id}")
    public void auditComplete(@PathVariable Long id){
        workOrderService.doAuditComplete(id);
    }

    @PostMapping("/delete")
    public void delete(@RequestBody List<Long> ids){
        workOrderService.doDelete(ids);
    }
}
